// pages/healthManage/report/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    code:"",
    workOrderCode:"",
    engineer:"",
    materials:"",
    dataList:[],
    completeTime:"",
    informationId:"",
    statusName:"",
    winHeight:"",
    list:"",
    iosDialog1:false,
    content:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self =this
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 140;
        console.log(calc)
        self.setData({
          winHeight: calc
        });
      }
    });
    const eventChannel = this.getOpenerEventChannel();
		// 监听 index页面定义的toHome 事件
		eventChannel.on('toreport', (res) => {
      console.log(res,'页面传值') 
      this.setData({
        code:res.code,
        workOrderCode:res.workOrderCode,
        list:res.list,
        statusName:res.statusName,
        informationId:res.informationId
      })
      self.getData()
    })
   
  },
  close: function () {
    this.setData({
        iosDialog1: false,
    })
},
  sureData(){
    let self = this;
    let obj = { list: self.data.list, informationId: self.data.informationId, type: 1 };
    let param = { code: self.data.code, workOrderCode: self.data.workOrderCode };
    self
    .axios
    .add("HealthControlExecute", obj, false)
    .then((res) => {
      if(res.code==200){
        wx.showToast({
          title: '保存成功',
          icon: 'succes',
          duration: 2000,
          success:()=>{
            wx.navigateBack({
            delta: 2
            })
          }
      })
      this.setData({
        iosDialog1: false,
    })
      }
  
    })
    .catch((e) => {
  
    });
  },
  sure(){
    let self = this
    let obj = { list: self.data.list, informationId: self.data.informationId, type: 1 };
    console.log(self.data.serialOrLotNumber)
    let checkObj={list: self.data.list,code: self.data.code, workOrderCode: self.data.workOrderCode,type:1,informationId: self.data.informationId}
    self
      .axios
      .custom("HealthControlRecordCheck", "checkRecord", checkObj)
      .then(function (response) {
        if(response.code==200){
          if(response.data.isOut==0){
            self
              .axios
              .add("HealthControlExecute", obj, false)
              .then((res) => {
                if(res.code==200){
                  wx.showToast({
                    title: '保存成功',
                    icon: 'succes',
                    duration: 2000,
                    success:()=>{
                      wx.navigateBack({
                      delta: 2
                      })
                    }
                })
                }
              })
              .catch((e) => {
              });
         }else{
           let content=""
           content=response.data.content.split(";")
           content.pop()
           console.log(content)
           self.setData({
             iosDialog1:true,
             content:content
           })
         }
        }
        console.log(response)

      });
    //   wx.navigateBack({
    //     delta: 2
    // })
  },
  getData() {
    let self = this;
    let obj = {};
    obj.code = self.data.code;
    obj.workOrderCode = self.data.workOrderCode
     self.axios.custom("HealthControlReport","report",obj ,false)
      .then(res=> {
        console.log(res)
        self.setData({
          materials:res.data.materials,
          dataList:res.data.list,
          completeTime:res.data.completeTime,
          engineer:res.data.engineer
        })

      })
      .catch(e=>{
        console.log(e)
      })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})